# -*- coding:utf-8 -*-
# __author__ : "张百科"
# Date: 2021/1/23 20:10
# File: category.py
# IDE: PyCharm
from rest_framework import serializers
from django.contrib.auth.models import User
from django.conf import settings
from models.category import Category
from rest_framework.validators import UniqueValidator

class CategorySerializer(serializers.ModelSerializer):

    name=serializers.CharField(label='分类名称', max_length=20,  help_text='分类名称',
                                 error_messages={
                                     ## 键值对，对应上面的限制条件，以及对应的提示
                                     'max_length': '最长20个字符'
                                 }
                                 )
    parent_id = serializers.IntegerField(label='所属分类', help_text='所属分类', required=False)
    logo = serializers.CharField(label='logo', help_text='logo', required=False)
    sort = serializers.IntegerField(label='排序', help_text='排序', required=False)
    level = serializers.IntegerField(label='层级', help_text='层级', required=False)
    remark = serializers.CharField(label='备注', max_length=500, help_text='备注', allow_blank=True,
                                   required=False,
                                   error_messages={
                                       'max_length': '最长500个字符'
                                   })
    class Meta:
        model = Category
        exclude = ('is_delete',)
